package com.mycompany.goodsys.core.AppEntity;

import java.util.ArrayList;
import java.util.List;

public class AppEntity {
    public static List<AppObj> obj_list = new ArrayList<AppObj>();

    public static List<AppObj> SelectObj(String name_condition){
        List<AppObj> list = new ArrayList<AppObj>();
        for(AppObj item : obj_list){
            if(item.GetName().contains(name_condition)){
                list.add(item.Clone());
            }
        }
        return list;
    }

    public static boolean AddObj(AppObj obj){
        if(obj == null) return false;

        for(AppObj item : obj_list){
            if(item.GetGuid().equals((obj.GetGuid()))){
                return false;
            }
        }
        obj_list.add(obj);
        return true;
    }

    public static boolean RemoveObj(String guid){
        if(guid == null || guid == ""){
            return false;
        }

        int index = -1;
        for(int i = 0;i < obj_list.size(); ++i){
            if(obj_list.get(i).GetGuid().equals(guid)){
                index = i;
                break;
            }
        }

        if(index == -1){
            return false;
        }

        obj_list.remove(index);
        return true;
    }

    public boolean ChengeObj(AppObj obj){
        if(obj == null) return false;

        int index = -1;
        String guid = obj.GetGuid();
        for(int i = 0;i < obj_list.size(); ++i){
            if(obj_list.get(i).GetGuid().equals(guid)){
                index = i;
                break;
            }
        }

        if(index == -1){
            return false;
        }

        AppObj go = obj_list.get(index);
        go.SetName(obj.GetName());
        go.SetNumber(obj.GetNumber());

        return true;
    }

}
